package br.atribuicoes.professor.producaoAcademica

import br.academia.Professor

class ComunicacaoController {

	def scaffold = Comunicacao


	def save = {
		def comunicacaoInstance = new Comunicacao(params)

		Professor professor = Professor.findByUsername(session.user)
		if (professor){

			if (comunicacaoInstance.save(flush: true)) {

				ProducaoAcademica producaoAcademica = new ProducaoAcademica()
				producaoAcademica.comunicacao = comunicacaoInstance
				producaoAcademica.dataCadastro = new Date()
				producaoAcademica.save()
				professor.addToProducoesAcademica(producaoAcademica)
				flash.message = "${message(code: 'default.created.message', args: [message(code: 'Comunicacao.label', default: 'Comunicacao'), comunicacaoInstance.id])}"
				redirect(action: "show", id: comunicacaoInstance.id)
			}else{
				flash.error = "ERROR"
				render(view: "create", model: [comunicacaoInstance: comunicacaoInstance])
			}
		}
		else {
			flash.message("Professor Invalido no Sistema!")
			render(view: "create", model: [comunicacaoInstance: comunicacaoInstance])
		}
	}
}
